package office.action.sale;

import java.util.List;

import javax.annotation.Resource;

import office.action.sale.form.CustomerCareConditionForm;
import office.action.sale.form.CustomerCareForm;
import office.action.sale.form.CustomerConditionForm;
import office.action.sale.wrapper.CustomerCareWrapper;
import office.action.sale.wrapper.CustomerWrapper;
import office.service.sale.ICustomerCareService;
import office.service.sale.ICustomerService;
import platform.common.action.BaseAction;
import platform.common.bo.Page;
import current.security.user.domain.User;
import current.security.user.manager.service.UserManagerService;

/**
 * 
 * 客户关怀
 * 
 * @author ZhangYQ
 * 
 */
public class CustomerCareAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	private ICustomerCareService customerCareService;
	private ICustomerService customerService;
	private Page page; // 分页信息
	private List<CustomerCareWrapper> wrapperList;
	private List<CustomerWrapper> customerWrapperList;
	private CustomerCareForm form;
	private CustomerCareConditionForm condition;
	private CustomerConditionForm customerCondition;
	private String id;
	private List<User> userList;
	@Resource
	private UserManagerService userManagerService;

	/**
	 * 获取所有的客户关怀以及根据条件进行查询
	 * 
	 * @return
	 * @throws Exception
	 */
	public String findAllCustomerCare() throws Exception {
		page = customerCareService.getPageInfo(condition);
		wrapperList = customerCareService.findAllCustomerCare(condition,page);
//		if(condition!=null){
//			return "listCustomerCareByPage";
//		}
		return "findAllCustomerCare";
	}

	/**
	 * 初始化编辑客户关怀页面
	 * @return
	 * @throws Exception
	 */
	public String gotoEditCustomerCare() throws Exception {
		if(null!=id&&!"".equals(id)){
			form = customerCareService.getById(id);
		}
		//获取当前负责人
		userList=userManagerService.getUserByRoleAndCompany("xsry,qyjl,xsjl",getUserCompanyId());
		customerCondition = new CustomerConditionForm();
		customerCondition.setWriteMan(getUserId());
		customerWrapperList=customerService.findAllCustomer(customerCondition);
		return "gotoEditCustomerCare";
	}

	/**
	 * 编辑客户关怀
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editCustomerCare() throws Exception {
		try {
			customerCareService.editCustomerCare(form);
			if (null == form.getId()
					|| ("").equals(form.getId())) {
				this.getAjaxMessagesJson().setMessage(true, "", "新建成功");
			} else {
				this.getAjaxMessagesJson().setMessage(true, "", "编辑成功");
			}

		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}

	/**
	 * 
	 * <br/>
	 * 方法描述:分页条件查询客户关怀结构
	 * 
	 * @return
	 * @throws Exception
	 */
	public String listCustomerCareByPage() throws Exception {
		try {
			wrapperList = customerCareService.findAllCustomerCare(condition, page);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return "findAllCustomerCare";
	}

	/**
	 * 初始化客户关怀结构列表操作菜单
	 * 
	 * @return
	 * @throws Exception
	 */

	public String gotoCustomerCareMenu() throws Exception {
		return "gotoCustomerCareMenu";
	}

	/**
	 * 跳转到客户关怀删除确认页面
	 */
	public String gotoDeleteCustomerCare(){
		return "gotoDeleteCustomerCare";
	}
	
	/**
	 * 删除客户关怀
	 * @return
	 * @throws Exception
	 */
	public String delCustomerCare() throws Exception {
		try {
			customerCareService.delCustomerCareById(id);
			this.getAjaxMessagesJson().setMessage(true, "", "操作成功");
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return RESULT_AJAXJSON;
	}

	public ICustomerCareService getCustomerCareService() {
		return customerCareService;
	}

	public void setCustomerCareService(ICustomerCareService customerCareService) {
		this.customerCareService = customerCareService;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public List<CustomerCareWrapper> getWrapperList() {
		return wrapperList;
	}

	public void setWrapperList(List<CustomerCareWrapper> wrapperList) {
		this.wrapperList = wrapperList;
	}

	public CustomerCareForm getForm() {
		return form;
	}

	public void setForm(CustomerCareForm form) {
		this.form = form;
	}

	public CustomerCareConditionForm getCondition() {
		return condition;
	}

	public void setCondition(CustomerCareConditionForm condition) {
		this.condition = condition;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public ICustomerService getCustomerService() {
		return customerService;
	}

	public void setCustomerService(ICustomerService customerService) {
		this.customerService = customerService;
	}

	public CustomerConditionForm getCustomerCondition() {
		return customerCondition;
	}

	public void setCustomerCondition(CustomerConditionForm customerCondition) {
		this.customerCondition = customerCondition;
	}

	public List<CustomerWrapper> getCustomerWrapperList() {
		return customerWrapperList;
	}

	public void setCustomerWrapperList(List<CustomerWrapper> customerWrapperList) {
		this.customerWrapperList = customerWrapperList;
	}

	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

	public UserManagerService getUserManagerService() {
		return userManagerService;
	}

	public void setUserManagerService(UserManagerService userManagerService) {
		this.userManagerService = userManagerService;
	}
	
	
}
